
# HBase 集群启动和基本使用

## 1. 启动集群
    ZK集群、HDFS集群、HBase集群
      zk.sh start
      hdp.sh hdfs
      hbs.sh start
        HMaster、HRegionServer
  启动后服务：
    [bwie@node101 ~]$ jpsall
      --------- node101 ----------
      1952 HMaster
      1697 DataNode
      1445 QuorumPeerMain
      1557 NameNode
      2104 HRegionServer
      --------- node102 ----------
      1734 HRegionServer
      1532 DataNode
      1422 QuorumPeerMain
      --------- node103 ----------
      1734 QuorumPeerMain
      2040 HRegionServer
      1838 DataNode

## 2. 命令行操作数据库
    先创建表，然后对表中数据进行CRUD操作（插入、读取、更新、删除）
    hbase shell
        回车即可
    # 创建表，指定表名称和列簇名称
    hbase(main):001:0> create 'student', 'info'
    # 查看有哪些表
    hbase(main):003:0> list
    # 插入-更新数据
    hbase(main):004:0> put 'student', '1001', 'info:name', 'zhangsan'
    hbase(main):005:0> put 'student', '1001', 'info:age', '25'
    hbase(main):007:0> put 'student', '1001', 'info:gender', 'male'
    hbase(main):008:0> put 'student', '1001', 'info:address', 'beijing'
    # 查看数据
    hbase(main):009:0> get 'student', '1001'
    COLUMN                                 CELL
     info:address                          timestamp=1761792206553, value=beijing
     info:age                              timestamp=1761792161470, value=25
     info:gender                           timestamp=1761792201526, value=male
     info:name                             timestamp=1761792139219, value=zhangsan
    Took 0.0549 seconds
    hbase(main):010:0> get 'student', '1001', 'info:age'
    COLUMN                                 CELL
     info:age                              timestamp=1761792161470, value=25
    # todo 实际项目，尤其表存储海量数据，不允许使用scan扫描数据
    hbase(main):018:0> scan 'student'
     ROW                                    COLUMN+CELL
      1001                                  column=info:address, timestamp=1761792206553, value=beijing
      1001                                  column=info:age, timestamp=1761792161470, value=25
      1001                                  column=info:gender, timestamp=1761792201526, value=male
      1001                                  column=info:name, timestamp=1761792139219, value=zhangsan
      1002                                  column=info:address, timestamp=1761792403189, value=shanghai
      1002                                  column=info:age, timestamp=1761792393874, value=24
      1002                                  column=info:gender, timestamp=1761792409286, value=male
      1002                                  column=info:job, timestamp=1761792426651, value=data enginer
      1002                                  column=info:name, timestamp=1761792387937, value=lisi
    # 删除数据
    hbase(main):019:0> delete 'student', '1002', 'info:job'
    hbase(main):021:0> deleteall 'student', '1002'
    # 表删除
    hbase(main):023:0> create 't1', 'info'
    hbase(main):029:0> disable 't1'
    hbase(main):030:0> drop 't1'


## 3. Java API操作数据库
    1). 添加依赖
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>${hbase.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-server</artifactId>
            <version>${hbase.version}</version>
        </dependency>

      文档：
        https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/package-summary.html
    2). 插入数据
      s1.连接   Connection
      s2.表     Table
      s3.插入   Put
      s4.执行   table.put(put)
      s5.关闭   close

    3). 读取数据
      s1.连接   Connection
      s2.表     Table
      s3.查询   Get
      s4.执行   table.get(get)
      s5.查看   Cell
      s6.关闭   close